package com.hgd.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.json.annotations.JSON;

import com.hgd.client.admin.AdminImplDelegate;
import com.hgd.client.admin.AdminImplService;
import com.hgd.client.init.InitImplDelegate;
import com.hgd.client.init.InitImplService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class InitAction extends ActionSupport {
	
	private int MSId;
	private Integer adminId;
	private int K;
	private String dir;
	InitImplService service = new InitImplService();
	InitImplDelegate delegate = service.getInitImplPort();
	
	AdminImplService adminImplService = new AdminImplService();
	AdminImplDelegate adminImplDelegate = adminImplService.getAdminImplPort();
	
	public String init() throws Exception{
		System.out.println(K);
		List<Integer> list = delegate.systemInit(adminId,K);
		MSId = list.get(0);
		K = list.get(1);
		Map<String, Object> session = ActionContext.getContext().getSession();
		if(session.get("MSId")!=null){
			session.put("MSId", MSId);
			session.put("Init", 1);		
		};
		return SUCCESS;
	}
	
	public String delete() throws Exception{
		MSId = delegate.msDel(adminId);
		Map<String, Object> session = ActionContext.getContext().getSession();
		if(session.get("MSId")!=null){
			session.put("MSId", MSId);
			session.put("Init", 0);
		};
		return SUCCESS;
	}
	
	public String dpsoinit() throws Exception{
		System.out.println(K);
		List<Integer> list = delegate.dpsoInit(adminId, K);
		MSId = list.get(0);
		K = list.get(1);
		Map<String, Object> session = ActionContext.getContext().getSession();
		if(session.get("MSId")!=null){
			session.put("MSId", MSId);
			session.put("Init", 1);		
		};
		return SUCCESS;
	}
	
	public String createInit() throws Exception{
		dir = delegate.createInit();
		String result;
		if (dir!=null) {
			result = SUCCESS;
		}else{
			result = ERROR;
		}
		return result;
	}
			
	public int getMSId() {
		return MSId;
	}

	public void setMSId(int mSId) {
		MSId = mSId;
	}
	public Integer getAdminId() {
		return adminId;
	}

	public void setAdminId(Integer adminId) {
		this.adminId = adminId;
	}
	@JSON(name="K") 
	public int getK() {
		return K;
	}

	public void setK(int k) {
		K = k;
	}
	@JSON(name="dir") 
	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}
	
}
